<?
    class Principio_Model_AccountLink
    {
        private $spa_id;
        private $accounts;

        public function __construct(&$values)
        {
            if (is_integer($values))
            {
                $this->spa_id = null;
                $this->accounts = array();
                for ($i = 0; $i < intval($values); $i++)
                    $this->accounts[] = array("id" => -1, "account_id" => -1, "ext_id" => $i);
            }
            else
            {
                $this->spa_id = $values['spa_id'];
                $this->accounts = $values['accounts'];
            };
        }


        public function getSpaID()
        {
            return $this->spa_id;
        }

        public function setSpaID($spa_id)
        {
            $spa_id_ = intval($spa_id);
            if ($spa_id_ < 1)
                return false;

            $this->spa_id = $spa_id_;
            return $this;
        }


        public function getLink($index)
        {
            $index_ = intval($index);
            if ( ($index_ < 1) || ($index_ > count($this->accounts) + 1))
                return false;

            return $this->accounts[$index_ - 1];
        }


        public function getID($index)
        {
            $index_ = intval($index);
            if ((count($this->accounts) > $index_) && ($index_ >= 0))
                return $this->accounts[$index_]['id'];
            else
                return false;
        }

        public function setID($index, $id)
        {
            $index_ = intval($index);
            if ((count($this->accounts) > $index_) && ($index_ >= 0))
            {
                $this->accounts[$index_]['id'] = intval($id);
                return $this;
            }
            else
                return false;
        }


        public function getLinkAccountID($index)
        {
            $index_ = intval($index);
            if ((count($this->accounts) > $index_) && ($index_ >= 0))
                return $this->accounts[$index_]['account_id'];
            else
                return false;
        }

        public function setLinkAccountID($index, $account_id)
        {
            $index_ = intval($index);
            if ((count($this->accounts) > $index_) && ($index_ >= 0))
            {
                $this->accounts[$index_]['account_id'] = $account_id;
                return $this;
            }
            else
                return false;

        }

        public function getExts()
        {
            return count($this->accounts);
        }
    }
?>